package com.bocai.dahuatech.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.AddressListBean;
import com.bocai.dahuatech.R;

import java.util.List;

public class MyAddressAdapter extends BaseAdapter {
    private Context context;
    List<AddressListBean.ContentEntity> datas;
    public MyAddressAdapter(Context context,List<AddressListBean.ContentEntity> datas){
        this.context=context;
        this.datas=datas;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.my_address_item,null);
        ViewHolder viewHolder=new ViewHolder();
        viewHolder.tvName= (TextView) convertView.findViewById(R.id.tv_addresslist_name);
        viewHolder.tvPhone= (TextView) convertView.findViewById(R.id.tv_addresslist_phone);
        viewHolder.tvContent= (TextView) convertView.findViewById(R.id.tv_addresslist_content);
        viewHolder.tvName.setText(datas.get(position).getFConsignee());
        viewHolder.tvPhone.setText(datas.get(position).getFMobilePhone());
        if(datas.get(position).isFDefault()){
            viewHolder.tvContent.setText(context.getResources().getString(R.string.addressdefalt)+ datas.get(position).getPCAName() + datas.get(position).getFAddress());
        }else{
            viewHolder.tvContent.setText(datas.get(position).getPCAName() + datas.get(position).getFAddress());
        }
        return convertView;
    }
    class ViewHolder{
        TextView tvName,tvPhone,tvContent;

    }
}
